<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>restful api笔记 | 仲灏小栈</title>
    <meta name="generator" content="VuePress 1.8.0">
    <link rel="icon" href="/img/favicon.ico">
    <meta name="description" content="专注web全栈学习与总结。JavaScript,js,ES6,TypeScript,vue,python,css3,html5,Node,git,github等技术文章。">
    <meta name="keywords" content="前端博客,个人技术博客,前端,前端开发,前端框架,web前端,前端面试题,技术文档,学习,面试,JavaScript,js,ES6,TypeScript,vue,python,css3,html5,Node,git,github,markdown">
    <meta name="baidu-site-verification" content="code-5CGlqw1B4p">
    <meta name="google-site-verification" content="PbO8RiLRwDnNwqNFNGnaxZnEFB3CqcGMCGoloYfQXV0">
    <meta name="theme-color" content="#11a8cd">
    
    <link rel="preload" href="/assets/css/0.styles.15972595.css" as="style"><link rel="preload" href="/assets/js/app.6e09c0e4.js" as="script"><link rel="preload" href="/assets/js/2.26fadcea.js" as="script"><link rel="preload" href="/assets/js/33.4f69bb69.js" as="script"><link rel="prefetch" href="/assets/js/10.29078de5.js"><link rel="prefetch" href="/assets/js/100.1775343f.js"><link rel="prefetch" href="/assets/js/101.03c2a233.js"><link rel="prefetch" href="/assets/js/102.2d566277.js"><link rel="prefetch" href="/assets/js/103.28f0aae6.js"><link rel="prefetch" href="/assets/js/104.98d074e6.js"><link rel="prefetch" href="/assets/js/105.a113c54b.js"><link rel="prefetch" href="/assets/js/106.fe975924.js"><link rel="prefetch" href="/assets/js/107.06b48459.js"><link rel="prefetch" href="/assets/js/108.650cfa65.js"><link rel="prefetch" href="/assets/js/109.8dea05a5.js"><link rel="prefetch" href="/assets/js/11.0ffc15c2.js"><link rel="prefetch" href="/assets/js/110.f426e949.js"><link rel="prefetch" href="/assets/js/111.cb0ff462.js"><link rel="prefetch" href="/assets/js/112.2234a7ce.js"><link rel="prefetch" href="/assets/js/113.d42a4afb.js"><link rel="prefetch" href="/assets/js/114.afa6c93d.js"><link rel="prefetch" href="/assets/js/115.e74e58c4.js"><link rel="prefetch" href="/assets/js/116.b52912dc.js"><link rel="prefetch" href="/assets/js/117.f5e176df.js"><link rel="prefetch" href="/assets/js/118.428fdb24.js"><link rel="prefetch" href="/assets/js/119.c7b3c702.js"><link rel="prefetch" href="/assets/js/12.5358dc27.js"><link rel="prefetch" href="/assets/js/120.b28cb8e3.js"><link rel="prefetch" href="/assets/js/121.517216d1.js"><link rel="prefetch" href="/assets/js/122.224b318f.js"><link rel="prefetch" href="/assets/js/123.04e6a56c.js"><link rel="prefetch" href="/assets/js/13.1eb6db46.js"><link rel="prefetch" href="/assets/js/14.2d919975.js"><link rel="prefetch" href="/assets/js/15.351e3a4c.js"><link rel="prefetch" href="/assets/js/16.3acd2d41.js"><link rel="prefetch" href="/assets/js/17.60b03995.js"><link rel="prefetch" href="/assets/js/18.c6ad362d.js"><link rel="prefetch" href="/assets/js/19.8ab677ff.js"><link rel="prefetch" href="/assets/js/20.99f99fea.js"><link rel="prefetch" href="/assets/js/21.c1d6f733.js"><link rel="prefetch" href="/assets/js/22.6f0b0c91.js"><link rel="prefetch" href="/assets/js/23.13368cdd.js"><link rel="prefetch" href="/assets/js/24.c53a9ca6.js"><link rel="prefetch" href="/assets/js/25.cd4407c5.js"><link rel="prefetch" href="/assets/js/26.d9b2ef17.js"><link rel="prefetch" href="/assets/js/27.16352eff.js"><link rel="prefetch" href="/assets/js/28.a62c7d25.js"><link rel="prefetch" href="/assets/js/29.635009f5.js"><link rel="prefetch" href="/assets/js/3.72d46b47.js"><link rel="prefetch" href="/assets/js/30.db885055.js"><link rel="prefetch" href="/assets/js/31.aa8c6cb9.js"><link rel="prefetch" href="/assets/js/32.e63d710c.js"><link rel="prefetch" href="/assets/js/34.9d242b1d.js"><link rel="prefetch" href="/assets/js/35.24c7045d.js"><link rel="prefetch" href="/assets/js/36.2988cd72.js"><link rel="prefetch" href="/assets/js/37.05bf63d5.js"><link rel="prefetch" href="/assets/js/38.ecef1ea2.js"><link rel="prefetch" href="/assets/js/39.0fde8ff2.js"><link rel="prefetch" href="/assets/js/4.d95386e0.js"><link rel="prefetch" href="/assets/js/40.99489203.js"><link rel="prefetch" href="/assets/js/41.928918ed.js"><link rel="prefetch" href="/assets/js/42.8ff04c77.js"><link rel="prefetch" href="/assets/js/43.347198e5.js"><link rel="prefetch" href="/assets/js/44.fc4d4540.js"><link rel="prefetch" href="/assets/js/45.5e4eff92.js"><link rel="prefetch" href="/assets/js/46.83a0c228.js"><link rel="prefetch" href="/assets/js/47.37c2f407.js"><link rel="prefetch" href="/assets/js/48.bada4ddc.js"><link rel="prefetch" href="/assets/js/49.562d8b65.js"><link rel="prefetch" href="/assets/js/5.77e36999.js"><link rel="prefetch" href="/assets/js/50.338be56f.js"><link rel="prefetch" href="/assets/js/51.999e3de3.js"><link rel="prefetch" href="/assets/js/52.11309761.js"><link rel="prefetch" href="/assets/js/53.ea6a0c8a.js"><link rel="prefetch" href="/assets/js/54.a49ee06c.js"><link rel="prefetch" href="/assets/js/55.d4d985f2.js"><link rel="prefetch" href="/assets/js/56.258972e6.js"><link rel="prefetch" href="/assets/js/57.e7d3b5af.js"><link rel="prefetch" href="/assets/js/58.50c14a49.js"><link rel="prefetch" href="/assets/js/59.8edb599b.js"><link rel="prefetch" href="/assets/js/6.ba658368.js"><link rel="prefetch" href="/assets/js/60.d1250584.js"><link rel="prefetch" href="/assets/js/61.28187287.js"><link rel="prefetch" href="/assets/js/62.1cb42759.js"><link rel="prefetch" href="/assets/js/63.3fd80d10.js"><link rel="prefetch" href="/assets/js/64.9f43af49.js"><link rel="prefetch" href="/assets/js/65.c4a47594.js"><link rel="prefetch" href="/assets/js/66.cd22b5d7.js"><link rel="prefetch" href="/assets/js/67.5c9918c9.js"><link rel="prefetch" href="/assets/js/68.fb876377.js"><link rel="prefetch" href="/assets/js/69.3414f481.js"><link rel="prefetch" href="/assets/js/7.83e78719.js"><link rel="prefetch" href="/assets/js/70.f003a000.js"><link rel="prefetch" href="/assets/js/71.39859d24.js"><link rel="prefetch" href="/assets/js/72.12912986.js"><link rel="prefetch" href="/assets/js/73.abd327ea.js"><link rel="prefetch" href="/assets/js/74.36cb7d1d.js"><link rel="prefetch" href="/assets/js/75.1cb96b9a.js"><link rel="prefetch" href="/assets/js/76.6033c6da.js"><link rel="prefetch" href="/assets/js/77.083624e2.js"><link rel="prefetch" href="/assets/js/78.70d3273c.js"><link rel="prefetch" href="/assets/js/79.14f3aecd.js"><link rel="prefetch" href="/assets/js/8.bcb11f96.js"><link rel="prefetch" href="/assets/js/80.95205bda.js"><link rel="prefetch" href="/assets/js/81.a39e63f0.js"><link rel="prefetch" href="/assets/js/82.6298e8dc.js"><link rel="prefetch" href="/assets/js/83.109c5547.js"><link rel="prefetch" href="/assets/js/84.6a1959a1.js"><link rel="prefetch" href="/assets/js/85.6ff6f61a.js"><link rel="prefetch" href="/assets/js/86.7d2bfbe7.js"><link rel="prefetch" href="/assets/js/87.2032d6ae.js"><link rel="prefetch" href="/assets/js/88.5cda9aa6.js"><link rel="prefetch" href="/assets/js/89.60c9e091.js"><link rel="prefetch" href="/assets/js/9.170a94b1.js"><link rel="prefetch" href="/assets/js/90.0dab9f57.js"><link rel="prefetch" href="/assets/js/91.ecf75d5a.js"><link rel="prefetch" href="/assets/js/92.74397fcb.js"><link rel="prefetch" href="/assets/js/93.f5559b26.js"><link rel="prefetch" href="/assets/js/94.27c65783.js"><link rel="prefetch" href="/assets/js/95.ea55ba1f.js"><link rel="prefetch" href="/assets/js/96.8a68510f.js"><link rel="prefetch" href="/assets/js/97.ef520b02.js"><link rel="prefetch" href="/assets/js/98.d4a41570.js"><link rel="prefetch" href="/assets/js/99.bdd726ad.js">
    <link rel="stylesheet" href="/assets/css/0.styles.15972595.css">
  </head>
  <body class="theme-mode-light">
    <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu have-body-img"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/img/logo.png" alt="仲灏小栈" class="logo"> <span class="site-name can-hide">仲灏小栈</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><a href="/web/" class="nav-link">大前端</a></div><div class="nav-item"><a href="/backend-opt/" class="nav-link">后端&amp;运维</a></div><div class="nav-item"><a href="/other-tech/" class="nav-link">其他</a></div><div class="nav-item"><a href="/tech-live/" class="nav-link">生活</a></div><div class="nav-item"><a href="/about/" class="nav-link">关于我</a></div><div class="nav-item"><a href="/favorite/" class="nav-link">收藏</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div> <a href="https://github.com/izhaong" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><div class="blogger"><img src="https://cdn.jsdelivr.net/gh/izhaong/izhaong.com-oss/site-data/avatar/avatar-wx.jpg"> <div class="blogger-info"><h3>仲灏</h3> <span>诚意, 正心, 格物, 致知</span></div></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">首页</a></div><div class="nav-item"><a href="/web/" class="nav-link">大前端</a></div><div class="nav-item"><a href="/backend-opt/" class="nav-link">后端&amp;运维</a></div><div class="nav-item"><a href="/other-tech/" class="nav-link">其他</a></div><div class="nav-item"><a href="/tech-live/" class="nav-link">生活</a></div><div class="nav-item"><a href="/about/" class="nav-link">关于我</a></div><div class="nav-item"><a href="/favorite/" class="nav-link">收藏</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/archives/" class="nav-link">归档</a></li></ul></div></div> <a href="https://github.com/izhaong" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>HTML&amp;CSS</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>JavaScript</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>Node</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/pages/febcd5/" class="sidebar-link">nvm 使用</a></li><li><a href="/pages/b378af/" class="sidebar-link">nvm 深度使用解析</a></li><li><a href="/pages/96c6f8/" class="sidebar-link">pnpm 学习</a></li><li><a href="/pages/8743eb/" class="sidebar-link">pnpm 使用及问题处理</a></li><li><a href="/pages/d15ce2/" class="sidebar-link">npm yarn pnpm命令对比</a></li><li><a href="/pages/037850/" class="sidebar-link">koa学习</a></li><li><a href="/pages/3e0a1c/" aria-current="page" class="active sidebar-link">restful api笔记</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/pages/3e0a1c/#http-options-方法的作用是什么" class="sidebar-link">HTTP options 方法的作用是什么 ？</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/pages/3e0a1c/#allowedmethods-的作用" class="sidebar-link">allowedMethods 的作用</a></li></ul></li><li class="sidebar-sub-header"><a href="/pages/3e0a1c/#restful-api-最佳实践-增删改查应该返回什么响应" class="sidebar-link">RESTful API 最佳实践--增删改查应该返回什么响应？</a></li><li class="sidebar-sub-header"><a href="/pages/3e0a1c/#错误处理" class="sidebar-link">错误处理</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/pages/3e0a1c/#异常状况" class="sidebar-link">异常状况</a></li><li class="sidebar-sub-header"><a href="/pages/3e0a1c/#为什么要用错误处理" class="sidebar-link">为什么要用错误处理</a></li><li class="sidebar-sub-header"><a href="/pages/3e0a1c/#操作步骤" class="sidebar-link">操作步骤</a></li><li class="sidebar-sub-header"><a href="/pages/3e0a1c/#自己编写错误处理中间件" class="sidebar-link">自己编写错误处理中间件</a></li><li class="sidebar-sub-header"><a href="/pages/3e0a1c/#使用-koa-json-error-进行错误处理" class="sidebar-link">使用 koa-json-error 进行错误处理</a></li><li class="sidebar-sub-header"><a href="/pages/3e0a1c/#使用-koa-parameter-校验参数-校验前端表单" class="sidebar-link">使用 koa-parameter 校验参数(校验前端表单)</a></li></ul></li><li class="sidebar-sub-header"><a href="/pages/3e0a1c/#字段过滤" class="sidebar-link">字段过滤</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/pages/3e0a1c/#设计schema默认隐藏部分字段" class="sidebar-link">设计schema默认隐藏部分字段</a></li><li class="sidebar-sub-header"><a href="/pages/3e0a1c/#通过查询字符串显示隐藏字段" class="sidebar-link">通过查询字符串显示隐藏字段</a></li></ul></li></ul></li><li><a href="/pages/1210/" class="sidebar-link">Egg.js 技巧</a></li><li><a href="/pages/9da7c4/" class="sidebar-link">Sequelize 学习笔记</a></li><li><a href="/pages/110928/" class="sidebar-link">npm 使用记录</a></li><li><a href="/pages/50e782/" class="sidebar-link">node 记错修复</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Vue</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>React</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>小程序</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>跨端</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Electron</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>浏览器</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>其他</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-0c557b5e><div class="articleInfo" data-v-0c557b5e><ul class="breadcrumbs" data-v-0c557b5e><li data-v-0c557b5e><a href="/" title="首页" class="iconfont icon-home router-link-active" data-v-0c557b5e></a></li> <li data-v-0c557b5e><a href="/web/#大前端" data-v-0c557b5e>大前端</a></li><li data-v-0c557b5e><a href="/web/#Node" data-v-0c557b5e>Node</a></li></ul> <div class="info" data-v-0c557b5e><div title="作者" class="author iconfont icon-touxiang" data-v-0c557b5e><a href="https://github.com/izhaong" target="_blank" title="作者" class="beLink" data-v-0c557b5e>仲灏</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-0c557b5e><a href="javascript:;" data-v-0c557b5e>2022-01-13</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-content"></div></div></div> <h1><img src="">restful api笔记<!----></h1> <!----> <div class="theme-vdoing-content content__default"><h2 id="http-options-方法的作用是什么"><a href="#http-options-方法的作用是什么" class="header-anchor">#</a> HTTP options 方法的作用是什么 ？</h2> <ul><li>检测服务器所支持的请求方法
发送options方式请求在返回的请求头Allow属性中可以看到支持的请求方法</li> <li>CORS 中的预检请求
如果一个网站的其中的一部分接口的一部分方法支持跨域，我们可检测该方法是否可以跨域</li></ul> <h3 id="allowedmethods-的作用"><a href="#allowedmethods-的作用" class="header-anchor">#</a> allowedMethods 的作用</h3> <ul><li>代码:<code>app.use(usersRouter.allowedMethods())</code> 加上它该路由都将支持options方法</li> <li>响应 options 方法， 告诉它所支持的请求方法
<img src="https://cdn.jsdelivr.net/gh/izhaong/izhaong.com-oss/blogImg/013041.restful%20api%E7%AC%94%E8%AE%B0/2022/01/13/16-19-24-fd23b1a08afc812e733435b1d988e7a5-watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxNjM2MTQw,size_16,color_FFFFFF,t_70-3d2dae.png" alt="在这里插入图片描述"> <ul><li>若没有使用此方法使用option方式请求就会报404错误
<img src="https://cdn.jsdelivr.net/gh/izhaong/izhaong.com-oss/blogImg/013041.restful%20api%E7%AC%94%E8%AE%B0/2022/01/13/16-19-27-bd7d2bd8f8cbb51874b6f6e77a485fd6-watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxNjM2MTQw,size_16,color_FFFFFF,t_70-20220113161914807-2e736a.png" alt="在这里插入图片描述"></li></ul></li> <li>相应的返回405（不允许）和501（没实现）
405： 支持该请求方法但是该接口功能未实现未写的时候
501： 不支持该请求方法是返回</li></ul> <h2 id="restful-api-最佳实践-增删改查应该返回什么响应"><a href="#restful-api-最佳实践-增删改查应该返回什么响应" class="header-anchor">#</a> RESTful API 最佳实践--增删改查应该返回什么响应？</h2> <p>增加修改返回该对象
删除返回204状态码
实例：</p> <div class="language-ode line-numbers-mode"><pre class="language-text"><code>usersRouter.delete('/:id', (ctx) =&gt; {
  ctx.status = 204
})
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h2 id="错误处理"><a href="#错误处理" class="header-anchor">#</a> 错误处理</h2> <ul><li>编程语言或计算机硬件里的一种机制</li> <li>处理软件或信息系统中出现的异常状况</li></ul> <h3 id="异常状况"><a href="#异常状况" class="header-anchor">#</a> 异常状况</h3> <ul><li>运行时错误, 都返回 500
建立在语法没有错误的基础上, 在运行时出现的错误, 如请求<code>undefined</code>时错误</li> <li>逻辑错误, 如
找不到(404) .
先决条件失败 ( 412 ) :  请求的<code>id</code>不存在
无法处理的实体 ( 参数格式不对 , 422 ) : 请求体参数格式不对
等..</li></ul> <h3 id="为什么要用错误处理"><a href="#为什么要用错误处理" class="header-anchor">#</a> 为什么要用错误处理</h3> <ul><li>防止程序挂掉
try...catch</li> <li>告诉用户错误信息
避免用户不知道错在哪里, 体验较差, 用户群体消失</li> <li>便于开发者调试</li></ul> <h3 id="操作步骤"><a href="#操作步骤" class="header-anchor">#</a> 操作步骤</h3> <ul><li>制造 404 , 412 , 500 三种错误</li></ul> <ol><li>404
<img src="https://cdn.jsdelivr.net/gh/izhaong/izhaong.com-oss/blogImg/013041.restful%20api%E7%AC%94%E8%AE%B0/2022/01/13/16-19-33-56b85a68ab27d4f2059af6ca5400e405-watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxNjM2MTQw,size_16,color_FFFFFF,t_70-20220113161914819-f323ad.png" alt="在这里插入图片描述"></li> <li>412</li></ol> <div class="language-js line-numbers-mode"><pre class="language-js"><code>  <span class="token function">findById</span><span class="token punctuation">(</span><span class="token parameter">ctx</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">if</span><span class="token punctuation">(</span>ctx<span class="token punctuation">.</span>params<span class="token punctuation">.</span>id <span class="token operator">*</span> <span class="token number">1</span> <span class="token operator">&gt;=</span> db<span class="token punctuation">.</span>length<span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token comment">// 不存在id时</span>
      ctx<span class="token punctuation">.</span><span class="token function">throw</span><span class="token punctuation">(</span><span class="token number">412</span><span class="token punctuation">,</span> <span class="token string">'先决条件失败, id 大于等于数组长度了'</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span>
    ctx<span class="token punctuation">.</span>body <span class="token operator">=</span> <span class="token punctuation">{</span> name<span class="token operator">:</span> <span class="token string">'lilei'</span> <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p><img src="https://cdn.jsdelivr.net/gh/izhaong/izhaong.com-oss/blogImg/013041.restful%20api%E7%AC%94%E8%AE%B0/2022/01/13/16-19-38-6a989be30eee251b10c9ba61020b9ae1-watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxNjM2MTQw,size_16,color_FFFFFF,t_70-20220113161914821-702972.png" alt="在这里插入图片描述">
3. 500</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>  <span class="token function">find</span><span class="token punctuation">(</span><span class="token parameter">ctx</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    ctx<span class="token punctuation">.</span>body <span class="token operator">=</span> a<span class="token punctuation">.</span>b
  <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><ul><li>了解 Koa 自带的错误处理做了什么</li></ul> <h3 id="自己编写错误处理中间件"><a href="#自己编写错误处理中间件" class="header-anchor">#</a> 自己编写错误处理中间件</h3> <p><strong>操作步骤</strong></p> <ul><li>自己编写错误处理中间件</li></ul> <div class="language-js line-numbers-mode"><pre class="language-js"><code>app<span class="token punctuation">.</span><span class="token function">use</span><span class="token punctuation">(</span><span class="token keyword">async</span><span class="token punctuation">(</span><span class="token parameter">ctx<span class="token punctuation">,</span> next</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
  <span class="token keyword">try</span> <span class="token punctuation">{</span>
    <span class="token keyword">await</span> <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span>err<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    
<span class="token comment">// message:&quot;先决条件失败, id 大于等于数组长度了&quot;</span>
<span class="token comment">// name:&quot;PreconditionFailedError&quot;</span>
<span class="token comment">// stack:&quot;PreconditionFailedError: 先决条件失败, id 大于等于数组长度了</span>
<span class="token comment">// expose:true</span>
<span class="token comment">// status:412</span>
<span class="token comment">// statusCode:412</span>
    ctx<span class="token punctuation">.</span>status <span class="token operator">=</span> err<span class="token punctuation">.</span>status <span class="token operator">||</span> err<span class="token punctuation">.</span>statusCode
    ctx<span class="token punctuation">.</span>body <span class="token operator">=</span> <span class="token punctuation">{</span>
      message<span class="token operator">:</span> err<span class="token punctuation">.</span>message
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br></div></div><ol start="2"><li>500
<code>ctx.status = err.status || err.statusCode || 500</code> <img src="https://cdn.jsdelivr.net/gh/izhaong/izhaong.com-oss/blogImg/013041.restful%20api%E7%AC%94%E8%AE%B0/2022/01/13/16-19-44-2eb272033f1602e5e012edf50b892e88-20200424004047531-47e7f4.png" alt="在这里插入图片描述"></li></ol> <ul><li>制造 404 , 412 , 500 三种错误来测试</li></ul> <h3 id="使用-koa-json-error-进行错误处理"><a href="#使用-koa-json-error-进行错误处理" class="header-anchor">#</a> 使用 <code>koa-json-error</code> 进行错误处理</h3> <p><img src="https://cdn.jsdelivr.net/gh/izhaong/izhaong.com-oss/blogImg/013041.restful%20api%E7%AC%94%E8%AE%B0/2022/01/13/16-19-46-888dbb572f3abfcda13382d2713d6179-watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxNjM2MTQw,size_16,color_FFFFFF,t_70-20220113161914862-95a1b5.png" alt="在这里插入图片描述"></p> <h3 id="使用-koa-parameter-校验参数-校验前端表单"><a href="#使用-koa-parameter-校验参数-校验前端表单" class="header-anchor">#</a> 使用 <code>koa-parameter</code> 校验参数(校验前端表单)</h3> <p><strong>参数不正确, 返回422</strong> <code>app.use(parameter(app))</code>不仅仅是一个中间件, 可以在ctx加上方法校验, 可以全局使用,所以传入app</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code>ctx<span class="token punctuation">.</span><span class="token function">verifyParams</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
      name<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> <span class="token string">'string'</span><span class="token punctuation">,</span> required<span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
      age<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> <span class="token string">'number'</span><span class="token punctuation">,</span> required<span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p><img src="https://cdn.jsdelivr.net/gh/izhaong/izhaong.com-oss/blogImg/013041.restful%20api%E7%AC%94%E8%AE%B0/2022/01/13/16-19-50-7fc9209cba096a5b61169c1eece193b5-watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQxNjM2MTQw,size_16,color_FFFFFF,t_70-20220113161914764-8c38a3.png" alt="在这里插入图片描述"></p> <p>补充：
<code>409</code>: 如新建用户，发现用户已存在，抛出错误</p> <h2 id="字段过滤"><a href="#字段过滤" class="header-anchor">#</a> 字段过滤</h2> <h3 id="设计schema默认隐藏部分字段"><a href="#设计schema默认隐藏部分字段" class="header-anchor">#</a> 设计schema默认隐藏部分字段</h3> <p>原返回</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token punctuation">{</span>
		<span class="token string">&quot;gender&quot;</span><span class="token operator">:</span> <span class="token string">&quot;male&quot;</span><span class="token punctuation">,</span>
		<span class="token string">&quot;locations&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
			<span class="token string">&quot;上海&quot;</span><span class="token punctuation">,</span>
			<span class="token string">&quot;北京&quot;</span>
		<span class="token punctuation">]</span><span class="token punctuation">,</span>
		<span class="token string">&quot;_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;5eadafda08d7180ecc1fb330&quot;</span><span class="token punctuation">,</span>
		<span class="token string">&quot;username&quot;</span><span class="token operator">:</span> <span class="token string">&quot;izhaong&quot;</span><span class="token punctuation">,</span>
		<span class="token string">&quot;employments&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
			<span class="token punctuation">{</span>
				<span class="token string">&quot;_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;5eadb33dfb66404e84c9fa57&quot;</span><span class="token punctuation">,</span>
				<span class="token string">&quot;company&quot;</span><span class="token operator">:</span> <span class="token string">&quot;biotree&quot;</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">]</span><span class="token punctuation">,</span>
		<span class="token string">&quot;educations&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
			<span class="token punctuation">{</span>
				<span class="token string">&quot;_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;5eadb33dfb66404e84c9fa58&quot;</span><span class="token punctuation">,</span>
				<span class="token string">&quot;school&quot;</span><span class="token operator">:</span> <span class="token string">&quot;皇家机电&quot;</span><span class="token punctuation">,</span>
				<span class="token string">&quot;major&quot;</span><span class="token operator">:</span> <span class="token string">&quot;钒钛资源利用技术&quot;</span><span class="token punctuation">,</span>
				<span class="token string">&quot;diploma&quot;</span><span class="token operator">:</span> <span class="token number">3</span><span class="token punctuation">,</span>
				<span class="token string">&quot;entrance_year&quot;</span><span class="token operator">:</span> <span class="token number">2014</span><span class="token punctuation">,</span>
				<span class="token string">&quot;graduation_year&quot;</span><span class="token operator">:</span> <span class="token number">2017</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">]</span><span class="token punctuation">,</span>
		<span class="token string">&quot;avatar&quot;</span><span class="token operator">:</span> <span class="token string">&quot;http://localhost:3000/upload/upload_7fb20d056f3d693d4bde34a2b4289783.jpeg&quot;</span><span class="token punctuation">,</span>
		<span class="token string">&quot;business&quot;</span><span class="token operator">:</span> <span class="token string">&quot;互联网&quot;</span><span class="token punctuation">,</span>
		<span class="token string">&quot;headline&quot;</span><span class="token operator">:</span> <span class="token string">&quot;诚意 正心 明理 格物 致知 修身 齐家&quot;</span>
	<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br></div></div><p>设计</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> userSchema <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Schema</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  __v<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> Number<span class="token punctuation">,</span> select<span class="token operator">:</span> <span class="token boolean">false</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
  username<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> String<span class="token punctuation">,</span> required<span class="token operator">:</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
  password<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> String<span class="token punctuation">,</span> required<span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> select<span class="token operator">:</span> <span class="token boolean">false</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
  avatar<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> String <span class="token punctuation">}</span><span class="token punctuation">,</span>
  gender<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> String<span class="token punctuation">,</span> <span class="token keyword">enum</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">'male'</span><span class="token punctuation">,</span> <span class="token string">'femele'</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token keyword">default</span><span class="token operator">:</span> <span class="token string">'male'</span><span class="token punctuation">,</span> required<span class="token operator">:</span> <span class="token boolean">true</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
  headline<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> String <span class="token punctuation">}</span><span class="token punctuation">,</span>
  locations<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">{</span> type<span class="token operator">:</span> String <span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">,</span> select<span class="token operator">:</span> <span class="token boolean">false</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
  business<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> String<span class="token punctuation">,</span> select<span class="token operator">:</span> <span class="token boolean">false</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
  employments<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">{</span> company<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> String <span class="token punctuation">}</span><span class="token punctuation">,</span> job<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> String <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">,</span> select<span class="token operator">:</span> <span class="token boolean">false</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
  educations<span class="token operator">:</span> <span class="token punctuation">{</span>
    type<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">{</span>
      school<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> String <span class="token punctuation">}</span><span class="token punctuation">,</span>
      major<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> String <span class="token punctuation">}</span><span class="token punctuation">,</span>
      diploma<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> Number<span class="token punctuation">,</span> <span class="token keyword">enum</span><span class="token operator">:</span> <span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">]</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
      entrance_year<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> Number <span class="token punctuation">}</span><span class="token punctuation">,</span>
      graduation_year<span class="token operator">:</span> <span class="token punctuation">{</span> type<span class="token operator">:</span> Number <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">,</span>  
  select<span class="token operator">:</span> <span class="token boolean">false</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br></div></div><p>设计之后</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token punctuation">{</span>
	<span class="token string">&quot;gender&quot;</span><span class="token operator">:</span> <span class="token string">&quot;male&quot;</span><span class="token punctuation">,</span>
	<span class="token string">&quot;_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;5eadafda08d7180ecc1fb330&quot;</span><span class="token punctuation">,</span>
	<span class="token string">&quot;username&quot;</span><span class="token operator">:</span> <span class="token string">&quot;izhaong&quot;</span><span class="token punctuation">,</span>
	<span class="token string">&quot;avatar&quot;</span><span class="token operator">:</span> <span class="token string">&quot;http://localhost:3000/upload/upload_7fb20d056f3d693d4bde34a2b4289783.jpeg&quot;</span><span class="token punctuation">,</span>
	<span class="token string">&quot;headline&quot;</span><span class="token operator">:</span> <span class="token string">&quot;诚意 正心 明理 格物 致知 修身 齐家&quot;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h3 id="通过查询字符串显示隐藏字段"><a href="#通过查询字符串显示隐藏字段" class="header-anchor">#</a> 通过查询字符串显示隐藏字段</h3> <p><code>mongoose</code>是支持<code>const user = await User.findById(ctx.params.id).select('+educations+business')</code>这种查询的
所以我们不能写死
处理得</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> <span class="token punctuation">{</span> fields <span class="token punctuation">}</span> <span class="token operator">=</span> ctx<span class="token punctuation">.</span>query
<span class="token comment">// f不能为空 过滤掉</span>
<span class="token keyword">const</span> selectFields <span class="token operator">=</span> fields<span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token string">';'</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">filter</span><span class="token punctuation">(</span><span class="token parameter">f</span> <span class="token operator">=&gt;</span> f<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span><span class="token parameter">f</span> <span class="token operator">=&gt;</span> <span class="token string">' +'</span> <span class="token operator">+</span> f<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">join</span><span class="token punctuation">(</span><span class="token string">''</span><span class="token punctuation">)</span>
<span class="token comment">// const user = await User.findById(ctx.params.id)</span>
<span class="token comment">// const user = await User.findById(ctx.params.id).select('+educations+business')</span>
<span class="token keyword">const</span> user <span class="token operator">=</span> <span class="token keyword">await</span> User<span class="token punctuation">.</span><span class="token function">findById</span><span class="token punctuation">(</span>ctx<span class="token punctuation">.</span>params<span class="token punctuation">.</span>id<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">select</span><span class="token punctuation">(</span>selectFields<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p><strong>查询</strong><code>/users/5eadafda08d7180ecc1fb330?fields=educations;business</code>得</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
	<span class="token property">&quot;gender&quot;</span><span class="token operator">:</span> <span class="token string">&quot;male&quot;</span><span class="token punctuation">,</span>
	<span class="token property">&quot;_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;5eadafda08d7180ecc1fb330&quot;</span><span class="token punctuation">,</span>
	<span class="token property">&quot;username&quot;</span><span class="token operator">:</span> <span class="token string">&quot;izhaong&quot;</span><span class="token punctuation">,</span>
	<span class="token property">&quot;educations&quot;</span><span class="token operator">:</span> <span class="token punctuation">[</span>
		<span class="token punctuation">{</span>
			<span class="token property">&quot;_id&quot;</span><span class="token operator">:</span> <span class="token string">&quot;5eadca0728cdd1bf308632de&quot;</span><span class="token punctuation">,</span>
			<span class="token property">&quot;school&quot;</span><span class="token operator">:</span> <span class="token string">&quot;皇家机电&quot;</span><span class="token punctuation">,</span>
			<span class="token property">&quot;major&quot;</span><span class="token operator">:</span> <span class="token string">&quot;钒钛资源利用技术&quot;</span><span class="token punctuation">,</span>
			<span class="token property">&quot;diploma&quot;</span><span class="token operator">:</span> <span class="token number">3</span><span class="token punctuation">,</span>
			<span class="token property">&quot;entrance_year&quot;</span><span class="token operator">:</span> <span class="token number">2014</span><span class="token punctuation">,</span>
			<span class="token property">&quot;graduation_year&quot;</span><span class="token operator">:</span> <span class="token number">2017</span>
		<span class="token punctuation">}</span>
	<span class="token punctuation">]</span><span class="token punctuation">,</span>
	<span class="token property">&quot;avatar&quot;</span><span class="token operator">:</span> <span class="token string">&quot;http://localhost:3000/upload/upload_7fb20d056f3d693d4bde34a2b4289783.jpeg&quot;</span><span class="token punctuation">,</span>
	<span class="token property">&quot;business&quot;</span><span class="token operator">:</span> <span class="token string">&quot;互联网&quot;</span><span class="token punctuation">,</span>
	<span class="token property">&quot;headline&quot;</span><span class="token operator">:</span> <span class="token string">&quot;诚意 正心 明理 格物 致知 修身 齐家&quot;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br></div></div></div></div> <!----> <div class="page-edit"><!----> <!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2022/01/21, 15:51:34</span></div></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/pages/037850/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">koa学习</div></a> <a href="/pages/1210/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">Egg.js 技巧</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/pages/037850/" class="prev">koa学习</a></span> <span class="next"><a href="/pages/1210/">Egg.js 技巧</a>→
      </span></p></div></div></div> <div class="article-list"><div class="article-title"><a href="/archives/" class="iconfont icon-bi">最近更新</a></div> <div class="article-wrapper"><dl><dd>01</dd> <dt><a href="/pages/486e07/"><div>
            Git Hooks
            <!----></div></a> <span class="date">02-24</span></dt></dl><dl><dd>02</dd> <dt><a href="/pages/f041f4/"><div>
            标准化编程规范解决方案
            <!----></div></a> <span class="date">02-24</span></dt></dl><dl><dd>03</dd> <dt><a href="/pages/2b68bd/"><div>
            git 提交信息规范
            <!----></div></a> <span class="date">02-24</span></dt></dl> <dl><dd></dd> <dt><a href="/archives/" class="more">更多文章&gt;</a></dt></dl></div></div></main></div> <div class="footer"><div class="icons"><a href="mailto:izhaong@outlook.com" title="发邮件" target="_blank" class="iconfont icon-youjian"></a><a href="https://github.com/izhaong" title="GitHub" target="_blank" class="iconfont icon-github"></a><a href="https://music.163.com/#/playlist?id=755597173" title="听音乐" target="_blank" class="iconfont icon-erji"></a></div> 
  Theme by
  <a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a> 
    | Copyright © 2021-2022
    <span>izhaong | <a href="https://github.com/izhaong" target="_blank">github</a> | <a href="http://beian.miit.gov.cn/" target="_blank">蜀ICP备2021031194号</a></span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
          跟随系统
        </li><li class="iconfont icon-rijianmoshi">
          浅色模式
        </li><li class="iconfont icon-yejianmoshi">
          深色模式
        </li><li class="iconfont icon-yuedu">
          阅读模式
        </li></ul></div></div> <div class="body-bg" style="background:url() center center / cover no-repeat;opacity:0.5;"></div> <!----> <!----></div><div class="global-ui"><div></div></div></div>
    <script src="/assets/js/app.6e09c0e4.js" defer></script><script src="/assets/js/2.26fadcea.js" defer></script><script src="/assets/js/33.4f69bb69.js" defer></script>
  </body>
</html>
